/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package servidor.auxiliar;

import java.io.ObjectOutputStream;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Hashtable;

/**
 *
 * @author ziza
 */
public class Arquivo {

    private Hashtable<String, DataCliente> online = null;

    public Arquivo() {
        online = new Hashtable<String, DataCliente>();
    }

    public Hashtable<String, DataCliente> getOnline() {
        return online;
    }

    public void adicionaOnline(DataCliente cliente) {
        online.put(cliente.getNickname(), cliente);
    }

    public DataCliente pesquisaCliente(String nickname) {

        if (online.containsKey(nickname)) {
            return (online.get(nickname));
        } else {
            return null;
        }
    }

    public void desliga(DataCliente cliente) {
        DataCliente user = this.pesquisaCliente(cliente.getNickname());
        if (this.online.get(user.getNickname()) != null) {
            online.remove(user.getNickname());
        }
    }

    public DataCliente pesquisaCanal(ObjectOutputStream out){

        Enumeration<DataCliente> en = online.elements();
        while(en.hasMoreElements()){
            DataCliente cliente = en.nextElement();
            if(cliente.getOut().equals(out))
                return cliente;
        }
        return null;
    }
}
